package com.maimang.platform.dsp.controller;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.dsp.entity.CampaignData;
import com.maimang.platform.dsp.service.CampaignDataService;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.page.TableDataInfo;
import com.maimang.platform.common.utils.ExcelUtil;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @classname CampaignDataController
 * @description <br>广告主数据信息操作处理</br>
 * @author  Rocky
 * @date    2019-11-26 11:23:37
 * @email   jintaozhao@qq.com
 * @version 1.0.0
 */
@Controller
@RequestMapping("/dsp/campaignData")
@Api(value = "广告主数据", description = "广告主数据 信息操作处理接口")
public class CampaignDataController extends BaseController {
    private String prefix = "dsp/campaignData";

	@Autowired
	private CampaignDataService campaignDataService;

	@RequiresPermissions("dsp:campaignData:view")
	@GetMapping()
	public String campaignData() {
	    return prefix + "/campaignData";
	}

	/**
	 * 查询广告主数据列表
	 */
	@ApiOperation(value = "查询列表", notes = "查询广告主数据列表信息")
	@RequiresPermissions("dsp:campaignData:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CampaignData campaignData) {
		startPage();
        List<CampaignData> list = campaignDataService.selectCampaignDataList(campaignData);
		return getDataTable(list);
	}


	/**
	 * 导出广告主数据列表
	 */
	@ApiOperation(value = "导出列表", notes = "导出广告主数据列表信息到Excel文件")
	@RequiresPermissions("dsp:campaignData:export")
    @PostMapping("/export")
    @ResponseBody
    public Result export(CampaignData campaignData) {
    	List<CampaignData> list = campaignDataService.selectCampaignDataList(campaignData);
        ExcelUtil<CampaignData> util = new ExcelUtil<CampaignData>(CampaignData.class);
        return util.exportExcel(list, "campaignData");
    }

	/**
	 * 新增广告主数据
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存广告主数据
	 */
	@ApiOperation(value = "新增保存", notes = "参数：CampaignData")
	@RequiresPermissions("dsp:campaignData:add")
	@Log(title = "广告主数据", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(CampaignData campaignData) {
		return toResult(campaignDataService.insertCampaignData(campaignData));
	}

	/**
	 * 修改广告主数据
	 */
	@GetMapping("/edit/{pkId}")
	public String edit(@PathVariable("pkId") Integer pkId, ModelMap modelMap) {
		CampaignData campaignData = campaignDataService.selectCampaignDataById(pkId);
		modelMap.put("campaignData", campaignData);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存广告主数据
	 */
	@ApiOperation(value = "修改保存", notes = "参数：CampaignData")
	@RequiresPermissions("dsp:campaignData:edit")
	@Log(title = "广告主数据", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(CampaignData campaignData) {
		return toResult(campaignDataService.updateCampaignData(campaignData));
	}

	/**
	 * 删除广告主数据
	 */
	@ApiOperation(value = "删除对象", notes = "参数：ids，示例： id1,id2,id3，接口会转转为String[]类型")
	@RequiresPermissions("dsp:campaignData:remove")
	@Log(title = "广告主数据", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(campaignDataService.deleteCampaignDataByIds(ids));
	}

}